using System;
using System.Collections.Generic;
using System.Text;
using Widgetsphere.GeneratorEngine;

namespace Omniture.API.Generators.Objects
{
	internal class PropRuntimeItemCollectionTemplate : BaseTemplate
	{
		internal PropRuntimeItemCollectionTemplate(OmnitureProject project)
			: base(project)
		{
		}

		public override string FileContent
		{
			get
			{
				StringBuilder sb = new StringBuilder();
				sb.AppendLine("using System;");
				sb.AppendLine("using System.Collections.Generic;");
				sb.AppendLine("using System.Collections.ObjectModel;");
				sb.AppendLine("using System.Text;");
				sb.AppendLine("using Omniture.Plugin.Objects;");
				sb.AppendLine();
				sb.AppendLine("namespace Omniture.Plugin");
				sb.AppendLine("{");
				sb.AppendLine("	[Serializable()]");
				sb.AppendLine("	public class PropRuntimeItemCollection : List<PropRuntimeItem>");
				sb.AppendLine("	{");
				sb.AppendLine("		#region Class Members");
				sb.AppendLine();
				sb.AppendLine("		public enum PropTypeConstants");
				sb.AppendLine("		{");
				foreach (PropItem item in this.Project.PropList)
				{
					sb.AppendLine("			/// <summary>");
					sb.AppendLine("			/// " + item.Description);
					sb.AppendLine("			/// </summary>");
					sb.AppendLine("			" + item.Name + ",");
				}
				sb.AppendLine("		}");
				sb.AppendLine();
				sb.AppendLine("		#endregion");
				sb.AppendLine();
				sb.AppendLine("		#region Constructors");
				sb.AppendLine();
				sb.AppendLine("		internal PropRuntimeItemCollection()");
				sb.AppendLine("			: base()");
				sb.AppendLine("		{");
				sb.AppendLine("		}");
				sb.AppendLine();
				sb.AppendLine("		internal PropRuntimeItemCollection(List<PropRuntimeItem> innerList)");
				sb.AppendLine("			: base(innerList)");
				sb.AppendLine("		{");
				sb.AppendLine("		}");
				sb.AppendLine();
				sb.AppendLine("		#endregion");
				sb.AppendLine();
				sb.AppendLine("		#region Methods");
				sb.AppendLine();
				sb.AppendLine("		public PropRuntimeItem this[string name]");
				sb.AppendLine("		{");
				sb.AppendLine("			get");
				sb.AppendLine("			{");
				sb.AppendLine("				foreach (PropRuntimeItem item in this)");
				sb.AppendLine("				{");
				sb.AppendLine("					if (item.Name == name)");
				sb.AppendLine("						return item;");
				sb.AppendLine("				}");
				sb.AppendLine("				return null;");
				sb.AppendLine("			}");
				sb.AppendLine("		}");
				sb.AppendLine();
				sb.AppendLine("		public PropRuntimeItem this[PropTypeConstants type]");
				sb.AppendLine("		{");
				sb.AppendLine("			get");
				sb.AppendLine("			{");
				foreach (PropItem item in this.Project.PropList)
				{
					sb.AppendLine("				if (type == PropTypeConstants." + item.Name + ") return this[\"" + item.Name + "\"];");
				}
				sb.AppendLine("				return null;");
				sb.AppendLine("			}");
				sb.AppendLine("		}");
				sb.AppendLine();
				sb.AppendLine("		#endregion");
				sb.AppendLine();

				#region Static Methods

				sb.AppendLine("		#region Methods");
				sb.AppendLine("		public static PropRuntimeItem CreateItem(PropTypeConstants type, string value)");
				sb.AppendLine("		{");
				sb.AppendLine("			switch (type)");
				sb.AppendLine("			{");
				foreach (ITrackItem item in this.Project.PropList)
				{
					sb.AppendLine("				case PropTypeConstants." + item.Name + ":");
					sb.AppendLine("					return new " + item.Name + "PropRuntimeItem(value, false);");
				}
				sb.AppendLine("			}");
				sb.AppendLine("			return null;");
				sb.AppendLine("		}");
				sb.AppendLine("		#endregion");
				sb.AppendLine();

				#endregion

				sb.AppendLine("	}");
				sb.AppendLine("}");
				sb.AppendLine();
				return sb.ToString();
			}
		}

		public static void Generate(OmnitureProject project, string destinationFolder)
		{
			PropRuntimeItemCollectionTemplate t = new PropRuntimeItemCollectionTemplate(project);
			t.Generate(destinationFolder);
		}

		public override string FileName
		{
			get { return @"PropRuntimeItemCollection.cs"; }
		}

	}
}
